﻿use core::{
    borrow::BorrowMut,
    cell::UnsafeCell,
    mem::MaybeUninit,
    marker::PhantomPinned,
};

use abs_smux::{TrMultiplex, TrPort};
use atomex::TrCmpxchOrderings;
use buffex::{
    ring_buffer::RingBuffer,
    x_deps::{abs_sync, abs_buff, atomex},
};

pub struct SimpleMux<BTx, BRx, Ord>
where
    BTx: BorrowMut<[MaybeUninit<u8>]>,
    BRx: BorrowMut<[MaybeUninit<u8>]>,
    Ord: TrCmpxchOrderings,
{
    _pinned_: PhantomPinned,
    tx_cell_: UnsafeCell<RingBuffer<BTx, u8, Ord>>,
    rx_cell_: UnsafeCell<RingBuffer<BRx, u8, Ord>>,
}

impl<BTx, BRx, Ord> SimpleMux<BTx, BRx, Ord>
where
    BTx: BorrowMut<[MaybeUninit<u8>]>,
    BRx: BorrowMut<[MaybeUninit<u8>]>,
    Ord: TrCmpxchOrderings,
{
    pub const fn new(
        tx: RingBuffer<BTx, u8, Ord>,
        rx: RingBuffer<BRx, u8, Ord>,
    ) -> Self {
        SimpleMux {
            _pinned_: PhantomPinned,
            tx_cell_: UnsafeCell::new(tx),
            rx_cell_: UnsafeCell::new(rx),
        }
    }
}
